package h_exception;

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) throws Exception {
        if(3<=name.length()&&name.length()<=10){
            this.name = name;
            if(age>=18&&age<=40){
                this.age = age;
            }else
                throw new ageException("年龄范围不在18-40请重新输入");
        }else {
            throw new nameException("姓名长度范围不在3-10请重新输入");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
